<template>
  <div class="app-container">
    <el-collapse-transition>
      <el-form v-if="openCondition" :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item label="隶属组" prop="groupId">
          <el-select v-model="queryParams.groupId" placeholder="请选择隶属组" filterable clearable size="small"
                     @change="this.groupChangeLoadApi">
            <el-option
              v-for="dict in groupOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="接口" prop="apiId">
          <el-select v-model="queryParams.apiId" placeholder="请选择接口" filterable clearable size="small">
            <el-option
              v-for="dict in apiOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="任务状态" prop="reqStatus">
          <el-select v-model="queryParams.reqStatus" placeholder="请选择任务状态" clearable size="small">
            <el-option
              v-for="dict in reqStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </el-collapse-transition>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:reqConfig:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:reqConfig:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:reqConfig:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5" style="float: right">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button :type="!openCondition?'success':'info'"
                   :icon="!openCondition?'el-icon-caret-bottom':'el-icon-caret-top'" size="mini"
                   @click="openCondition=!openCondition">{{!openCondition?'展开条件':'收起条件'}}
        </el-button>
      </el-col>
    </el-row>

    <el-table :data="configList" height="580" @sort-change="handleSortChange" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!-- <el-table-column label="序号" width="50">
         <template scope="scope">
           <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
         </template>
       </el-table-column>-->
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="配置名称" align="center" prop="configName" width="220"/>
      <el-table-column label="组名称" align="center" prop="groupId.name"/>
      <el-table-column label="接口名称" align="center" prop="apiId.name"/>
      <el-table-column label="线程数" align="center" prop="threadNum"/>
      <el-table-column label="发起" align="center" prop="startNum"/>
      <el-table-column label="成功" align="center" prop="finishNum"/>
      <el-table-column label="终止" align="center" prop="stopNum"/>
      <el-table-column label="进度" align="center" prop="progress" width="120">
        <template slot-scope="scope">
          <el-progress v-if="scope.row.pageNum/scope.row.pageTotal !== 1"
                       :percentage="scope.row.reqStatus.key ==1?0:((scope.row.pageNum/scope.row.pageTotal)*100).toFixed(2) * 1.0"></el-progress>

          <el-progress v-if="scope.row.pageNum/scope.row.pageTotal === 1" status="success"
                       :percentage="scope.row.reqStatus.key ==4?100:((scope.row.pageNum/scope.row.pageTotal)*100).toFixed(2) * 1.0"></el-progress>
        </template>
      </el-table-column>
      <el-table-column label="任务状态" align="center" prop="reqStatus">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.reqStatus.key ==='1'" type="info" size="medium">{{ scope.row.reqStatus.value }}
          </el-tag>
          <el-tag v-if="scope.row.reqStatus.key ==='2'" type="warning" size="medium">{{ scope.row.reqStatus.value }}
          </el-tag>
          <el-tag v-if="scope.row.reqStatus.key ==='3'" type="success" size="medium">{{ scope.row.reqStatus.value }}
          </el-tag>
          <el-tag v-if="scope.row.reqStatus.key ==='4'" type="danger" size="medium">{{ scope.row.reqStatus.value }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="请求标志" align="center" prop="lastReqId" width="220"/>
      <el-table-column label="操作" align="center" fixed="right" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.reqStatus.key === '1' || scope.row.reqStatus.key === '4'"
            size="mini"
            type="text"
            icon="el-icon-video-play"
            style="color:#67C23A"
            @click="handleExcute(scope.row)"
            v-hasPermi="['system:reqConfig:start']"
          >执行
          </el-button>
          <el-button
            v-if="scope.row.reqStatus.key === '2'"
            size="mini"
            type="text"
            icon="el-icon-d-arrow-right"
            style="color:#67C23A"
            @click="handleContinue(scope.row)"
            v-hasPermi="['system:reqConfig:continue']"
          >继续
          </el-button>
          <el-button
            v-if="scope.row.reqStatus.key === '3'"
            size="mini"
            type="text"
            icon="el-icon-video-pause"
            style="color:#E6A23C"
            @click="handlePause(scope.row)"
            v-hasPermi="['system:reqConfig:pause']"
          >暂停
          </el-button>
          <el-button
            v-if="scope.row.reqStatus.key === '3'"
            size="mini"
            type="text"
            icon="el-icon-switch-button"
            style="color:#F56C6C"
            @click="handleStop(scope.row)"
            v-hasPermi="['system:reqConfig:stop']"
          >停止
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleView(scope.row)"
          >详情
          </el-button>
          <el-button
            v-if="scope.row.reqStatus.key === '1' || scope.row.reqStatus.key === '4'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:reqConfig:edit']"
          >修改
          </el-button>
          <el-button
            v-if="scope.row.reqStatus.key === '1' || scope.row.reqStatus.key === '4'"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:reqConfig:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改请求任务配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px">
      <!-- 修改 -->
      <el-form v-if="this.edit" ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="任务名称" prop="configName">
          <el-input v-model="form.configName" placeholder="请输入任务配置名称"/>
        </el-form-item>
        <el-form-item label="隶属组" prop="groupId">
          <el-select v-model="form.groupId" placeholder="请选择隶属组" filterable clearable size="small"
                     @change="this.groupChangeLoadApiUpdate">
            <el-option
              v-for="dict in groupOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="接口" prop="apiId">
          <el-select v-model="form.apiId" placeholder="请选择接口" filterable clearable size="small">
            <el-option
              v-for="dict in apiUpdateOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="请求数据组" title="custom:num:1:10000:2" prop="reqDataId">
          <el-select v-model="form.reqDataId" multiple filterable allow-create default-first-option
                     placeholder="请选择请求数据组" clearable
                     style="width:570px">
            <el-option
              v-for="dict in dataDropDownOptions"
              :key="dict.theName"
              :label="dict.theName"
              :value="dict.theName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="代理服务" prop="proxyHost">
          <el-select v-model="form.proxyHost" filterable placeholder="请选择代理服务">
            <el-option
              v-for="dict in proxyHostOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel+'('+dict.dictValue+')'"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="超时时间" prop="timeOut">
          <el-input v-model="form.timeOut" type="number" placeholder="请输入超时时间(毫秒)"/>
        </el-form-item>
        <el-form-item label="延时时间" prop="intervalTime">
          <el-input v-model="form.intervalTime" type="number" placeholder="请输入延时时间(毫秒)"/>
        </el-form-item>
        <el-form-item label="线程数" prop="threadNum">
          <el-input v-model="form.threadNum" type="number" placeholder="请输入线程数"/>
        </el-form-item>
        <el-form-item label="分页大小" prop="pageSize">
          <el-input v-model="form.pageSize" type="number" placeholder="请输入分页大小"/>
        </el-form-item>
        <el-form-item label="魔法变量" prop="extraVar">
          <el-input v-model="form.extraVar" type="textarea" placeholder="key1: value1
key2: value2"/>
        </el-form-item>
        <el-form-item label="匹配模式" prop="matchType">
          <el-select v-model="form.matchType" placeholder="请选择结果匹配模式">
            <el-option
              v-for="dict in matchTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="匹配表达式" prop="matchPattern">
          <el-input v-model="form.matchPattern" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="存储结果配置" prop="storeVar">
          <el-input v-model="form.storeVar" type="textarea" placeholder="titleName: jsonPath
titleName2: jsonPath2"/>
        </el-form-item>
        <el-form-item label="保存完整结果" prop="isRetainResults">
          <el-select v-model="form.isRetainResults" placeholder="请选择">
            <el-option
              v-for="dict in isSaveOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <!-- 添加 -->
      <el-form v-if="!this.edit" ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="任务名称" prop="configName">
          <el-input v-model="form.configName" placeholder="请输入任务配置名称"/>
        </el-form-item>
        <el-form-item label="隶属组" prop="groupId">
          <el-select v-model="form.groupId" placeholder="请选择隶属组" filterable clearable size="small"
                     @change="this.groupChangeLoadApiUpdate">
            <el-option
              v-for="dict in groupOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="接口" prop="apiId">
          <el-select v-model="form.apiId" placeholder="请选择接口" filterable clearable size="small">
            <el-option
              v-for="dict in apiUpdateOptions"
              :key="dict.id"
              :label="dict.theName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="请求数据组" prop="reqDataId">
          <el-select v-model="form.reqDataId" multiple filterable allow-create default-first-option default-first-option
                     placeholder="请选择请求数据组" clearable
                     style="width:570px">
            <el-option
              v-for="dict in dataDropDownOptions"
              :key="dict.theName"
              :label="dict.theName"
              :value="dict.theName"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="代理服务" prop="proxyHost">
          <el-select v-model="form.proxyHost" filterable placeholder="请选择代理服务">
            <el-option
              v-for="dict in proxyHostOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel+'('+dict.dictValue+')'"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="超时时间" prop="timeOut">
          <el-input v-model="form.timeOut" type="number" placeholder="请输入超时时间(毫秒)"/>
        </el-form-item>
        <el-form-item label="延时时间" prop="timeOut">
          <el-input v-model="form.intervalTime" type="number" placeholder="请输入延时时间(毫秒)"/>
        </el-form-item>
        <el-form-item label="线程数" prop="threadNum">
          <el-input v-model="form.threadNum" type="number" placeholder="请输入线程数"/>
        </el-form-item>
        <el-form-item label="分页大小" prop="pageSize">
          <el-input v-model="form.pageSize" type="number" placeholder="请输入分页大小"/>
        </el-form-item>
        <el-form-item label="魔法变量" prop="extraVar">
          <el-input v-model="form.extraVar" type="textarea" placeholder="key1: value1
key2: value2"/>
        </el-form-item>
        <el-form-item label="匹配模式" prop="matchType">
          <el-select v-model="form.matchType" placeholder="请选择结果匹配模式">
            <el-option
              v-for="dict in matchTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="匹配表达式" prop="matchPattern">
          <el-input v-model="form.matchPattern" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="存储结果配置" prop="storeVar">
          <el-input v-model="form.storeVar" type="textarea" placeholder="titleName: jsonPath
titleName2: jsonPath2"/>
        </el-form-item>
        <el-form-item label="保存完整结果" prop="isRetainResults">
          <el-select v-model="form.isRetainResults" placeholder="请选择">
            <el-option
              v-for="dict in isSaveOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" size="mini">确 定</el-button>
        <el-button @click="cancel" size="mini">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 请求任务配置详情 -->
    <el-dialog title="请求任务配置详情" :visible.sync="viewOpen" width="750px">
      <el-form :inline="true" class="detail-inline" label-width="140px">
        <el-form-item label="任务名称：">
          <input class="bird-view-info-input" disabled :title="viewData.configName"
                 :value="viewData.configName"/>
        </el-form-item>
        <el-form-item label="隶属组：">
          <input class="bird-view-info-input" disabled :title="viewData.groupId && viewData.groupId.name"
                 :value="viewData.groupId && viewData.groupId.name"/>
        </el-form-item>
        <el-form-item label="请求接口：">
          <input class="bird-view-info-input" disabled :title="viewData.apiId && viewData.apiId.name"
                 :value="viewData.apiId && viewData.apiId.name"/>
        </el-form-item>
        <el-form-item label="延时时间：">
          <input class="bird-view-info-input" disabled :title="viewData.intervalTime" :value="viewData.intervalTime"/>
        </el-form-item>
        <el-form-item label="超时时间：">
          <input class="bird-view-info-input" disabled :title="viewData.timeOut" :value="viewData.timeOut"/>
        </el-form-item>
        <el-form-item label="线程数：">
          <input class="bird-view-info-input" disabled :title="viewData.threadNum" :value="viewData.threadNum"/>
        </el-form-item>
        <el-form-item label="请求数据：">
          <input class="bird-view-info-input" disabled :title="viewData.reqDataId" :value="viewData.reqDataId"/>
        </el-form-item>
        <el-form-item label="代理服务：">
          <input class="bird-view-info-input" disabled :title="viewData.proxyHost && viewData.proxyHost.value"
                 :value="viewData.proxyHost && viewData.proxyHost.value"/>
        </el-form-item>
        <el-form-item label="魔法变量：">
          <textarea cols="63" disabled class="bird-view-info-input" type="textarea">{{viewData.extraVar}}</textarea>
        </el-form-item>
        <el-form-item label="匹配模式：">
          <input class="bird-view-info-input" disabled :title="viewData.matchType" :value="viewData.matchType"/>
        </el-form-item>
        <el-form-item style="width: 100%;" label="匹配表达式：">
          <div style="color: #606266;width:700px;" v-html="viewData.matchPattern"></div>
        </el-form-item>
        <el-form-item label="存储结果配置：">
          <textarea cols="63" disabled class="bird-view-info-input" type="textarea">{{viewData.storeVar}}</textarea>
        </el-form-item>
        <el-form-item label="保存完整结果：">
          <input class="bird-view-info-input" disabled :title="viewData.isRetainResults"
                 :value="viewData.isRetainResults"/>
        </el-form-item>
        <el-form-item label="终止次数：">
          <input class="bird-view-info-input" disabled :title="viewData.stopNum" :value="viewData.stopNum"/>
        </el-form-item>
        <el-form-item label="成功次数：">
          <input class="bird-view-info-input" disabled :title="viewData.finishNum" :value="viewData.finishNum"/>
        </el-form-item>
        <el-form-item label="发起次数：">
          <input class="bird-view-info-input" disabled :title="viewData.startNum" :value="viewData.startNum"/>
        </el-form-item>
        <el-form-item label="分页大小：">
          <input class="bird-view-info-input" disabled :title="viewData.pageSize" :value="viewData.pageSize"/>
        </el-form-item>
        <el-form-item label="当前页：">
          <input class="bird-view-info-input" disabled :title="viewData.pageNum" :value="viewData.pageNum"/>
        </el-form-item>
        <el-form-item label="总页数：">
          <input class="bird-view-info-input" disabled :title="viewData.pageTotal" :value="viewData.pageTotal"/>
        </el-form-item>
        <el-form-item label="任务状态：">
          <input class="bird-view-info-input" disabled :title="viewData.reqStatus" :value="viewData.reqStatus"/>
        </el-form-item>
        <el-form-item label="创建人：">
          <input class="bird-view-info-input" disabled :title="viewData.creSb && viewData.creSb.name"
                 :value="viewData.creSb && viewData.creSb.name"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false" size="mini">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    addConfig,
    continueConfig,
    delConfig,
    getConfig,
    listConfig,
    pauseConfig,
    startConfig,
    stopConfig,
    updateConfig
  } from "@/api/system/apiConfig";
  import {listGroup} from "@/api/system/group";
  import {listApi} from "@/api/system/api";
  import {dropDownData} from "@/api/system/data";

  export default {
    data() {
      return {
        // 条件展开
        openCondition: true,
        // 是否修改
        edit: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 请求任务配置表格数据
        configList: [],
        // 弹出层标题
        title: "",
        // 是否显示详情弹出层
        viewOpen: false,
        // 是否显示弹出层
        open: false,
        // 结果匹配模式字典
        matchTypeOptions: [],

        // 任务状态字典
        reqStatusOptions: [],

        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderByColumn: 'id',
          isAsc: 'desc'
        },
        // 详情参数
        viewData: {},
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          id: [
            {required: true, message: "主键不能为空", trigger: "blur"}
          ],
          apiId: [
            {required: true, message: "接口不能为空", trigger: "blur"}
          ],
          intervalTime: [
            {required: true, message: "延时时间不能为空", trigger: "blur"}
          ],
          timeOut: [
            {required: true, message: "超时时间不能为空", trigger: "blur"}
          ],
          configName: [
            {required: true, message: "任务名称不能为空", trigger: "blur"}
          ],
          isRetainResults: [
            {required: true, message: "保留结果不能为空", trigger: "blur"}
          ],
          threadNum: [
            {required: true, message: "线程数不能为空", trigger: "blur"}
          ],
          reqDataId: [
            {required: true, message: "请求数据不能为空", trigger: "blur"}
          ],
          matchType: [
            {required: true, message: "结果匹配模式不能为空", trigger: "blur"}
          ],
          matchPattern: [
            {required: true, message: "结果匹配表达式不能为空", trigger: "blur"}
          ],
          pageSize: [
            {required: true, message: "分页大小不能为空", trigger: "blur"}
          ],
          proxyHost: [
            {required: true, message: "代理地址不能为空", trigger: "blur"}
          ],
          extraVar: [
            {required: false, message: "请输入格式正确的参数", trigger: "blur", pattern: "([^:]+:[^\\n:]+)+"}
          ],
          storeVar: [
            {required: false, message: "请输入格式正确的参数", trigger: "blur", pattern: "([^:]+:[^\\n:]+)+"}
          ],
        },
        groupOptions: [],
        apiOptions: [],
        apiUpdateOptions: [],
        dataDropDownOptions: [],
        isSaveOptions: [],
        proxyHostOptions: [],
      };
    },
    created() {
      this.getList();
      this.getDicts("MatchTypeEnum").then(response => {
        this.matchTypeOptions = response.data;
      });
      this.getDicts("ReqStatusEnum").then(response => {
        this.reqStatusOptions = response.data;
      });
      this.getDicts("ProxyHostEnum").then(response => {
        this.proxyHostOptions = response.data;
      });
      // 是否类型
      this.getDicts("sys_yes_no").then(response => {
        this.isSaveOptions = response.data;
      });

      // 隶属组查询
      const maxPageParams = {
        pageNum: 1,
        pageSize: 1000,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
      listGroup(maxPageParams).then(response => {
        this.groupOptions = response.data.list;
      });

      // 接口数据查询
      dropDownData().then(response => {
        this.dataDropDownOptions = response.data;
      });

    },
    methods: {
      /** 查询请求任务配置列表 */
      getList() {
        listConfig(this.queryParams).then(response => {
          this.configList = response.data.list;
          this.total = response.data.total;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.resetPropField(this.form);
        this.clearForm('form');
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetPropField(this.queryParams, {pageNum: 1, pageSize: 10, orderByColumn: 'id', isAsc: 'desc'});
        this.handleQuery();
      },
      // 排序改变事件
      handleSortChange(sorter) {
        this.handleSort(this.queryParams, sorter);
        this.getList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 详细按钮操作 */
      handleView(row) {
        const id = row.id
        getConfig(id).then(response => {
          const {data} = response;
          console.log(response);
          this.viewData = {
            ...data,
            isRetainResults: data.isRetainResults && data.isRetainResults.value,
            matchType: data.matchType && data.matchType.value,
            reqStatus: data.reqStatus && data.reqStatus.value,
            proxyHost: data.proxyHost && data.proxyHost.value,
          }
          this.viewOpen = true;
        });
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.edit = false;
        this.open = true;
        this.title = "添加请求任务配置";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.edit = true;
        this.reset();
        const id = row.id || this.ids
        getConfig(id).then(response => {
          const {data} = response;
          console.log(response);
          this.form = {
            ...data,
            isRetainResults: data.isRetainResults && data.isRetainResults.key,
            matchType: data.matchType && data.matchType.key,
            reqStatus: data.reqStatus && data.reqStatus.key,
            proxyHost: data.proxyHost && data.proxyHost.key,
            reqDataId: data.reqDataId && data.reqDataId.split(",")
          }
          this.groupChangeLoadApiUpdate(this.form.groupId.id);
          this.form.apiId = data.apiId.id
          this.open = true;
          this.title = "修改请求任务配置";
        });
      },
      /** 提交按钮 */
      submitForm: function () {
        this.$refs["form"].validate(valid => {
          if (valid) {
            // 数组值切换
            if (this.form.reqDataId) {
              this.form.reqDataId = this.form.reqDataId.join(",");
            }
            if (this.form.id != undefined) {
              updateConfig(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addConfig(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除请求任务配置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delConfig(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
      },
      groupChangeLoadApi(groupId) {
        // 隶属组查询
        const maxPageParams = {
          pageNum: 1,
          pageSize: 1000,
          orderByColumn: 'id',
          isAsc: 'desc',
          groupId: groupId
        }
        listApi(maxPageParams).then(response => {
          this.apiOptions = response.data.list;
        });
      },
      groupChangeLoadApiUpdate(groupId) {
        // 隶属组查询
        const maxPageParams = {
          pageNum: 1,
          pageSize: 1000,
          orderByColumn: 'id',
          isAsc: 'desc',
          groupId: groupId
        }
        listApi(maxPageParams).then(response => {
          this.apiUpdateOptions = response.data.list;
        });
      },
      handleExcute(row) {
        startConfig(row.id).then(response => {
          this.msgSuccess("开始执行！");
          this.getList();
        });
      },
      handlePause(row) {
        pauseConfig(row.id).then(response => {
          this.msgSuccess("暂停执行！");
          this.getList();
        });
      },
      handleContinue(row) {
        continueConfig(row.id).then(response => {
          this.msgSuccess("继续执行！");
          this.getList();
        });
      },
      handleStop(row) {
        stopConfig(row.id).then(response => {
          this.msgSuccess("终止执行！");
          this.getList();
        });
      }
    }
  };
</script>
